package gorefit

import (
	"time"
	"html"
)

const (
	DEBUG   = 1
	WARNING = 2
	ERROR   = 3
)

type Message struct {
	Time time.Time
	Text string
	Type int
}

func NewError(text string) *Message {
	msg := new(Message)
	msg.Time = time.Now()
	msg.Text = text
	msg.Type = ERROR
	return msg
}

func NewWarning(text string) *Message {
	msg := new(Message)
	msg.Time = time.Now()
	msg.Text = text
	msg.Type = WARNING
	return msg
}

func NewDebug(text string) *Message {
	msg := new(Message)
	msg.Time = time.Now()
	msg.Text = text
	msg.Type = DEBUG
	return msg
}

func (self *Message) HTMLRow() string {
	style := ""
	stype := ""
	switch self.Type {
	case ERROR:
		style = "color: white; background: red;"
		stype = "ERROR"
		break
	case WARNING:
		style = "color: black; background: yellow;"
		stype = "WARNING"
		break
	case DEBUG:
		style = "color: black; background: green;"
		stype = "DEBUG"
		break
	}
	return "<tr><td style=\"" + style + "\">" + stype + "</td><td style=\"font-weight: bold;\">" + string(self.Time.String()) + "</td><td>" + html.EscapeString(self.Text) + "</td></tr>"
}
